package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api(tags = "外卖套餐功能")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * @return Result<PageResult>
     * @throws
     * @description 套餐分页查询功能
     * @author Administrator
     * @param[1] dto
     * @time 2023/11/28 17:44
     */
    @GetMapping("/page")
    @ApiOperation("套餐分页查询功能")
    public Result<PageResult> pageSelectSetmeal(SetmealPageQueryDTO dto) {

        log.info("正在执行套餐分页查询功能.............查询信息为:{}", dto);

        PageResult p = setmealService.pageSelectSetmeal(dto);

        return Result.success(p);

    }

    /**
     * @return Result<SetmealVO>
     * @throws
     * @description 根据id查询套餐的功能
     * @author Administrator
     * @param[1] id
     * @time 2023/11/28 17:58
     */

    @ApiOperation("根据id查询套餐的功能")
    @GetMapping("/{id}")
    public Result<SetmealVO> selectSetmealById(@PathVariable Long id) {

        log.info("正在执行根据id查询套餐功能.......查询的id为:{}", id);

        SetmealVO setmealVO = setmealService.selectSetmealById(id);

        return Result.success(setmealVO);
    }


    /**
     * @return Result
     * @throws
     * @description 新增菜品的功能
     * @author Administrator
     * @param[1] setmealDTO
     * @time 2023/11/28 21:01
     */
    @ApiOperation("新添套餐的功能")
    @PostMapping
    public Result insertSetmeal(@RequestBody SetmealDTO setmealDTO) {


        log.info("正在执行新添套餐的功能...........新添的套餐信息为:{}", setmealDTO);

        setmealService.insertSetmeal(setmealDTO);

        return Result.success();

    }

    /**
     * @return Result
     * @throws
     * @description 修改套餐的功能
     * @author Administrator
     * @param[1] setmealDTO
     * @time 2023/11/28 21:01
     */

    @ApiOperation("修改套餐的功能")
    @PutMapping
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO) {
        log.info("正在执行修改套餐的功能............修改的套餐信息为:{}", setmealDTO);

        setmealService.updateSetmeal(setmealDTO);

        return Result.success();
    }

    /**
     * @return Result
     * @throws
     * @description 套餐的起售停售功能
     * @author Administrator
     * @param[1] status
     * @param[2] id
     * @time 2023/11/28 21:14
     */
    @ApiOperation("套餐的起售停售功能")
    @PostMapping("/status/{status}")
    public Result statusStartOrStop(@PathVariable Integer status, Long id) {

        log.info("套餐的起售停售功能............状态为:{},套餐id为:{}", status, id);

        setmealService.statusStartOrStop(status, id);

        return Result.success();

    }
/**
 * @description 批量删除套餐的功能
 * @author Administrator
 * @param[1] ids
 * @throws
 * @return Result
 * @time 2023/11/29 9:42
 */
    @ApiOperation("批量删除套餐")
    @DeleteMapping
    public Result deleteSetmeal(@RequestParam List<Long> ids) {

        log.info("正在执行删除套餐的功能.........id为:{}", ids);

        setmealService.deleteSetmeal(ids);

        return Result.success();
    }

}
